package com.shujia.java.day14.ListToMapDemo1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapEntry {
    public static void main(String[] args) {
        HashMap<Integer, Student> map = new HashMap<Integer, Student>();
        //使用构造创建student
        Student student = new Student(10001,"张三",18,"男");
        Student student1 = new Student(10002,"李四",18,"男");
        Student student2 = new Student(10003,"王五",18,"男");
        Student student3 = new Student(10004,"赵六",18,"男");

        Student student4 = new Student(10010,"赵六13213",18,"男");

        map.put(student.getId(),student);
        map.put(student1.getId(),student1);
        map.put(student2.getId(),student2);
        map.put(student3.getId(),student3);

        Set<Map.Entry<Integer, Student>> entries = map.entrySet();
        //见到集合 遍历
        for (Map.Entry<Integer, Student> entry:entries) {
            //Map.Entry<Integer, Student> 引用类型的对象
            // System.out.println(entry);
            //需改map.entrySet()中Value HashMap也发生修改
            entry.setValue(student4);
            System.out.println(entry.getKey()+"------------"+entry.getValue().getName());
        }
        //遍历
        //遍历map 获取所有key 通过key来过去value
        Set<Integer> integers = map.keySet();
        for (Integer i:integers){
            //输出id 和name
            System.out.println(i+"--------------"+map.get(i).getName());
        }
        //遍历 Entry 返回的值 KV都返回
        // 泛型套泛型 一个限制 限定数据结构 第二个限制 限制数据结构


    }
}
